package www.openteam.com.presenter.policy;

import java.util.HashMap;
import java.util.List;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.ApprovalStatu;
import www.openteam.com.bean.ReceivableApproval;
import www.openteam.com.contract.policy.ReceivableApprovalContract;
import www.openteam.com.model.policy.ReceivableApprovalModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.policy.ReceivablesApprovalFragment;

/**
 * Created by hyd on 2017/1/15.
 */

public class ReceivableApprovalPresenter
        extends BasePresenter<ReceivablesApprovalFragment>
    implements ReceivableApprovalContract.ReceivableApprovalPresenter {

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new ReceivableApprovalModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String ,IModel> hashMap = new HashMap<>();
        hashMap.put("queryReceivableApproval",models[0]);

        return hashMap;
    }

    @Override
    public void queryReceivableApproval(String custid,
                                        long startTime, long endTime,int orderStatus,
                                          String stype, String moreCom, int PageSize) {
        ((ReceivableApprovalModel)
                getiModelMap().get("queryReceivableApproval"))
                .queryReceivableApproval(custid, startTime, endTime, orderStatus, stype,   moreCom, PageSize,
                        new ReceivableApprovalModel.ReceivableApprovalOnListener() {
                            @Override
                            public void queryRASuccess(List<ReceivableApproval.DataEntity> orderApprovals) {
                                getIView().queryRASuccess(orderApprovals);
                            }

                            @Override
                            public void queryRAFail(String failMsg) {
                                getIView().queryRAFail(failMsg);
                            }
                        });
    }

    @Override
    public void unReApprovalUpdate(int id) {
        ( (ReceivableApprovalModel) getiModelMap().get("queryReceivableApproval"))
                .unReApprovalUpdate(id, new ReceivableApprovalModel.ReceivableOrderUOnListener() {
                    @Override
                    public void unApprovalRASuccess(ApprovalStatu aprovalStatu) {

                        getIView().unApprovalRASuccess(aprovalStatu);

                    }

                    @Override
                    public void unApprovalRAFail(String failMsg) {
                        getIView().unApprovalRAFail(failMsg);
                    }
                });
    }


    @Override
    public void reApprovalUpdate(int id) {
        ( (ReceivableApprovalModel) getiModelMap().get("queryReceivableApproval"))
                .reApprovalUpdate(id, new ReceivableApprovalModel.ReceivableOrderAOnListener(){
                    @Override
                    public void approvalRASuccess(ApprovalStatu aprovalStatu) {
                        getIView().approvalRASuccess(aprovalStatu);
                    }
                    @Override
                    public void approvalRAFail(String failMsg) {
                        getIView().approvalRAFail(failMsg);
                    }
                });
    }
}
